//
//  ShoppingCarViewController.m
//  AmountBody
//
//  Created by smm on 2017/12/5.
//  Copyright © 2017年 RCMTM. All rights reserved.
//

#import "ShoppingCarViewController.h"
#import "ShoppingCarTableViewCell.h"
#import "ShoppingCollectionViewCell.h"
#import "ShoppingCollectionReusableView.h"
#import "ShoppingCollectionModel.h"
#import "OrderProcessingViewController.h"

#import "EqualCellSpaceFlowLayout.h"
#import "ShoppingColorModel.h"
#import "TypeModel.h"
#import <ReactiveObjC/ReactiveObjC.h>
#import <AmountBody-Swift.h>

#import "SidebarView.h"

static const CGFloat HeadView_Tag = 903000;
static const CGFloat Image_Tag = 902000;
static const CGFloat itemHeight = 30;

@interface ShoppingCarViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UITextFieldDelegate,UIPickerViewDelegate,UIPickerViewDataSource,UICollectionViewDelegateFlowLayout>
@property (weak, nonatomic) IBOutlet UIView *searchView;
@property (weak, nonatomic) IBOutlet UITextField *s_text;
@property (weak, nonatomic) IBOutlet UIImageView *s_image;

@property (weak, nonatomic) IBOutlet UIView *downView;
@property (weak, nonatomic) IBOutlet UIButton *d_chooseButton;
- (IBAction)d_chooseButton:(UIButton *)sender;

@property (weak, nonatomic) IBOutlet UILabel *d_chooseLabel;
@property (weak, nonatomic) IBOutlet UIButton *d_delegateButton;
- (IBAction)d_delegateButton:(UIButton *)sender;

@property (weak, nonatomic) IBOutlet UILabel *d_countNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *d_countValueLabel;
@property (weak, nonatomic) IBOutlet UILabel *d_saveNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *d_saveValueLabel;
@property (weak, nonatomic) IBOutlet UIButton *d_tuoGuanButton;
- (IBAction)d_tuoGuanButton:(UIButton *)sender;

@property (weak, nonatomic) IBOutlet UIButton *d_jiesuanButton;
- (IBAction)d_jiesuanButton:(UIButton *)sender;

@property (weak, nonatomic) IBOutlet UITableView *tableView;
//搜索侧边栏选择弹出框
@property (strong, nonatomic) SidebarView *screenBackView;
//@property (weak, nonatomic) IBOutlet UIView *screenView;
//@property (weak, nonatomic) IBOutlet UIView *cancelView;
//color选择弹出框
@property (weak, nonatomic) IBOutlet UIButton *colorBackView;
- (IBAction)colorBackView:(UIButton *)sender;

@property (weak, nonatomic) IBOutlet UIView *colorView;
@property (weak, nonatomic) IBOutlet UIImageView *colorImage;
@property (weak, nonatomic) IBOutlet UIButton *c_saveButton;
@property (weak, nonatomic) IBOutlet UIView *c_scrollView;
@property (weak, nonatomic) IBOutlet UILabel *c_scrollNameLabel;
@property (weak, nonatomic) IBOutlet UIScrollView *c_scroll;
@property (weak, nonatomic) IBOutlet UIView *c_textView;
@property (weak, nonatomic) IBOutlet UILabel *c_textNameLabel;
@property (weak, nonatomic) IBOutlet UITextField *c_text;
@property (weak, nonatomic) IBOutlet UIView *c_lineView;

- (IBAction)c_saveButton:(UIButton *)sender;

//预提交弹框
@property (weak, nonatomic) IBOutlet UIButton *YTJBackView;
- (IBAction)YTJBackView:(UIButton *)sender;

@property (weak, nonatomic) IBOutlet UIView *YTJView;
@property (weak, nonatomic) IBOutlet UIImageView *YTJImage;

@property (weak, nonatomic) IBOutlet UIView *liningChooseView;//面料选择View
@property (weak, nonatomic) IBOutlet UIButton *YTJ_lButton;
- (IBAction)YTJ_lButton:(UIButton *)sender;

@property (weak, nonatomic) IBOutlet UILabel *YTJ_lLabel;
@property (weak, nonatomic) IBOutlet UIView *defaultView;//默认VIew
@property (weak, nonatomic) IBOutlet UIImageView *YTJ_dImage;
@property (weak, nonatomic) IBOutlet UILabel *YTJ_dLabel;
@property (weak, nonatomic) IBOutlet UIButton *matchingButton;//匹配button
- (IBAction)matchingButton:(id)sender;

@property (weak, nonatomic) IBOutlet UIScrollView *YTJScrollView;
@property (weak, nonatomic) IBOutlet UIView *YTJ_sOptionView;
@property (weak, nonatomic) IBOutlet UIView *YTJ_sNewsView;
@property (weak, nonatomic) IBOutlet UIImageView *YTJ_sNewsBackImage;
@property (weak, nonatomic) IBOutlet UIImageView *YTJ_sHeadImage;
@property (weak, nonatomic) IBOutlet UILabel *YTJ_sHeadLabel;
@property (weak, nonatomic) IBOutlet UIView *YTJ_sLineView;
@property (weak, nonatomic) IBOutlet UIScrollView *YTJ_sContentScrollView;

//弹出pickerView

@property (strong, nonatomic) IBOutlet UIView *tanchuView;
@property (strong, nonatomic) IBOutlet UIPickerView *tanChuPickerView;
@property (strong, nonatomic) IBOutlet UIButton *doneButton;
@property (strong, nonatomic) IBOutlet UIButton *clearButton;
- (IBAction)doneButton:(id)sender;
- (IBAction)clearButton:(id)sender;

@property (nonatomic,strong) ValuationFormulaView *formulaView;//计价公式View

//提交订单界面
@property (nonatomic,strong) NSTimer *timer;
@property (nonatomic,assign) NSInteger repeatNum;
@property (nonatomic,strong) NSMutableArray *mArray;
//@property (nonatomic,strong) ShoppingCarOrderLCView *shopView;


//数据
@property (strong, nonatomic) NSMutableArray * dataArray;
@property (strong, nonatomic) NSMutableArray * colorArray;
@property (assign, nonatomic) BOOL isChoose;//删除订单全选按钮
@property (strong, nonatomic) UICollectionView *collectionView;
@property (strong, nonatomic) NSMutableArray * nameArray;
@property (strong, nonatomic) NSMutableArray * c_dataArray;
@property (strong, nonatomic) NSMutableArray * colorViewArray;
@property (strong, nonatomic) NSString * nameStr;
@property (strong, nonatomic) NSString * idStr;
@property (assign, nonatomic) BOOL isClass;//是否点击搜索筛选
@property (assign, nonatomic) BOOL isMTM;//是否是MTM面料
@property (strong, nonatomic) PublicBlankView *kongPage;
@property (strong, nonatomic) ShoppingCarModel *model;
@property (assign, nonatomic) int c_index;//颜色选择的第几个
@property (strong, nonatomic) NSMutableArray * typeArr;//用于pickerView类型数组
@end

@implementation ShoppingCarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = RGBColorAlpha(240, 240, 240, 1);
    NSString * name = GDLocalizedString(@"shopping_cart");
    self.title = name;
    self.public_headView.hidden = NO;
    self.public_headView.titleLabel = [self titleLabel];
    self.public_headView.rightButton = [self rightButton];
    [self loadArrayData];
    [self loadUI];
    [self loadC_DataArray];
    [self loadUIForScreenView];
    [self loadKongPage];
    [self loadUIForColorView];
    [self loadUIForYTJ];
    // Do any additional setup after loading the view.
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [SidebarView blockForCancelView:^{
        [_screenBackView hiddenSidebarView];
        _isClass = NO;
        self.public_headView.rightButton = [self rightButton];
    }];
    [ShoppingCarTableViewCell blockForColorChooseView:^(ShoppingCarModel *model) {
        _model = model;
        
        [self loadUIForColorView];
        _colorBackView.hidden = NO;
    }];
    [PublicBlankView clickPublicBlankFunction:^{
        NSLog(@"点击了按钮");
    }];
    [ShoppingCarTableViewCell blockForButtonType:^(ButtonType type) {
        switch (type) {
            case ButtonTypeForTG:
            {
                
            }
                break;
            case ButtonTypeForMTO:
            {
                
            }
                break;
            case ButtonTypeForYTJ:
            {
                [self loadUIForYTJ];
                _YTJBackView.hidden = NO;
                
                
            }
                break;
            case ButtonTypeForBJ:
            {
                
            }
                break;
            case ButtonTypeForZCGM:
            {
                
            }
                break;
            case ButtonTypeForSC:
            {
                
            }
                break;
            default:
                break;
        }
        NSLog(@"%d",type);
        
    }];
}
-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    
}

#pragma mark - 懒加载

- (NSMutableArray *)dataArray;
{
    if (!_dataArray) {
        _dataArray = [[NSMutableArray array]init];
    }
    return _dataArray;
}
- (NSMutableArray *)typeArr;
{
    if (!_typeArr) {
        _typeArr = [[NSMutableArray array]init];
    }
    return _typeArr;
}
- (NSMutableArray *)nameArray;
{
    if (!_nameArray) {
        _nameArray = [[NSMutableArray array]init];
    }
    return _nameArray;
}
- (NSMutableArray *)c_dataArray;
{
    if (!_c_dataArray) {
        _c_dataArray = [[NSMutableArray array]init];
    }
    return _c_dataArray;
}
- (NSMutableArray *)colorArray;
{
    if (!_colorArray) {
        _colorArray = [[NSMutableArray array]init];
    }
    return _colorArray;
}
- (NSMutableArray *)mArray{
    
    if (_mArray == nil) {
        _mArray = [[NSMutableArray alloc]init];
    }
    return _mArray;
}
- (NSMutableArray *)colorViewArray {
    
    if (!_colorViewArray) {
        CGFloat jianGeW = 8;
        CGFloat jianGeH = 8;
        CGFloat buttonH = (_c_scroll.frame.size.height-jianGeH)/2.0;
        CGFloat buttonW = buttonH;
        _colorViewArray = [[NSMutableArray alloc]init];
        for (int i=0; i<_colorArray.count; i++) {
            ShoppingColorModel * model = [_colorArray objectAtIndex:i];
            int j = i/2;
            int k = i%2;
            UIImageView * image = [[UIImageView alloc]initWithFrame:CGRectMake((jianGeW+buttonW)*j, (jianGeH+buttonH)*k, buttonW, buttonH)];
            
            image.userInteractionEnabled = YES;
            UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(colorChoose:)];
            image.tag = Image_Tag+i;
            [image addGestureRecognizer:tap];
            
            image.userInteractionEnabled = YES;
            UIImageView * l_image =[[UIImageView alloc]initWithFrame:CGRectMake(0, jianGeH, buttonW-jianGeW, buttonH-jianGeH)];
            [l_image setYuanJiaoForRadius:5.0 andMasks:YES];
            l_image.userInteractionEnabled = YES;
            l_image.backgroundColor = model.color;
            CGFloat w_buttonW = 60;
            CGFloat w_buttonH = w_buttonW/42.*44;
            UIImageView * w_image = [[UIImageView alloc]initWithFrame:CGRectMake(image.frame.size.width-w_buttonW, 0, w_buttonW, w_buttonH)];
            if (model.isChoose) {
                w_image.image = [UIImage imageNamed:@"colorXuan"];
            }else{
                w_image.image = [UIImage imageNamed:@""];
            }
            
            [image addSubview:l_image];
            [image addSubview:w_image];
            [_c_scroll addSubview:image];
            [_colorViewArray addObject:image];
        }
        
    }
    
    return _colorViewArray;
}

-(void)loadArrayData
{
    NSArray * typeArray = [NSArray arrayWithObjects:@"斜纹倒顺毛",@"横纹",@"竖纹",@"棱角格",@"四方条纹",@"黑白间隔",@"点纹",@"小点纹", nil];
    
    for (int i=0; i<typeArray.count; i++) {
        TypeModel *model = [[TypeModel alloc]init];
        model.name = [typeArray objectAtIndex:i];
        [self.typeArr addObject:model];
    }
    for (int i=0; i<10; i++) {
        ShoppingCarModel *model = [[ShoppingCarModel alloc]init];
        model.name = @"客户1";
        model.title = @"2015秋款女士大衣系列第四款";
        model.time = @"2017-12-18 12:09:08";
        model.number = @"37654930";
        model.order_number  = @"fsfh8y9909";
        model.price = @"99.99";
        if (i%2 == 0) {
            model.hasAdd = YES;
        }else{
            model.hasAdd = NO;
        }
        if (i%3 == 0) {
            model.type = @"净";
        }else if(i%3 == 1){
            model.type = @"成";
        }else{
            model.type = @"标";
        }
        
        model.tagName = @"极度缺货";
        model.tagColor = [UIColor blueColor];
        [self.dataArray addObject:model];
    }
    
    for (int i=0; i<20; i++) {
        ShoppingColorModel * tmpmodel = [[ShoppingColorModel alloc]init];
        tmpmodel.color = [self randomColor];
        tmpmodel._id = [NSString stringWithFormat:@"%d",i];
        if (i == 0) {
            tmpmodel.isChoose = YES;
        }else{
            tmpmodel.isChoose = NO;
        }
        [self.colorArray addObject:tmpmodel];
    }
}
-(void)loadC_DataArray
{
    NSArray * nameArray = [NSArray arrayWithObjects:@"订单状态",@"订单类型",@"尺寸分类",@"客户账号",@"产品分类",@"我的标签", nil];
    NSArray * childArray = [NSArray arrayWithObjects:@[@"全部",@"保存中",@"托管",@"审核失败",@"锁定",@"未锁定",@"匹配问题",@"保存中",@"托管",@"审核失败",@"锁定",@"未锁定",@"匹配问题"],@[@"全部",@"自主设计",@"代码下单",@"看图下单",@"物料物资",@"新看图下单"],@[@"全部",@"净体量体",@"成衣尺寸",@"标准号加减"],@[@"全部",@"XXB",@"TEST12",@"XXB-TEXT"],@[@"全部",@"牛仔",@"套装",@"男士衬衫",@"女士西装",@"男士西装",@"男士西裤",@"女士西裤",@"女士衬衣"], @[@"全部",@"极度缺货",@"面料短缺",@"收藏注释"],nil];
    for (int i=0; i<nameArray.count; i++) {
        ShoppingCollectionModel * model = [[ShoppingCollectionModel alloc]init];
        model.title = [nameArray objectAtIndex:i];
        model._id = [NSString stringWithFormat:@"%d",i];
        model.childArr = [NSMutableArray arrayWithArray:[childArray objectAtIndex:i]];
        for (int j=0; j<model.childArr.count; j++) {
            ShoppingCollectionModel * tmpModel = [[ShoppingCollectionModel alloc]init];
            tmpModel.title = [model.childArr objectAtIndex:j];
            UILabel * label = [[UILabel alloc]init];
            label.text = tmpModel.title;
            label.font = Cell_Little_Font;
            [label sizeToFit];
            if (i==5) {
                tmpModel.size = CGSizeMake(label.frame.size.width+50, itemHeight);
            }else{
                tmpModel.size = CGSizeMake(label.frame.size.width+20, itemHeight);
            }
            tmpModel._id = [NSString stringWithFormat:@"%d",i*100+j];
            [model.childArr replaceObjectAtIndex:j withObject:tmpModel];
        }
        [self.c_dataArray addObject:model];
    }
}
#pragma mark -  UI布局
- (UIButton*)rightButton
{
    CGFloat buttonW = 44;
    CGFloat buttonH = 44;
    CGFloat jianGeW = 25;
    CGRect buttonFrame = CGRectMake(SCREEN_W-buttonW-jianGeW , 30, buttonW, buttonH);
    
    UIButton *button = [[UIButton alloc] initWithFrame:buttonFrame];
    [button addTarget:self action:@selector(rightButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    button.titleLabel.textAlignment = NSTextAlignmentCenter;
    //    [button setTitle:@"搜索" forState:UIControlStateNormal];
    
    if (_isClass) {
        [button setTitle:@"确认" forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@""] forState:UIControlStateSelected];
    }else{
        [button setTitle:@"" forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"CombinedShape"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"CombinedShape"] forState:UIControlStateSelected];
    }
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:15];
    [button sizeToFit];
    return button;
}


-(void)rightButtonPressed
{
    CGFloat viewW = SCREEN_W/2.0+120;
    CGFloat jianGeW = SCREEN_W-viewW;
    CGFloat viewH = SCREEN_H-TOPNAVIGATIONBAR_H-USERDEFINED_TABBAR_H;
    _isClass = !_isClass;
    if (_isClass) {
        
        self.public_headView.rightButton = [self rightButton];
        _screenBackView.hidden = NO;
        [_screenBackView showSidebarView];

    }else{
        self.public_headView.rightButton = [self rightButton];
        [_screenBackView hiddenSidebarView];
    }
    
}

#pragma mark --- 筛选侧边栏
-(void)loadUIForScreenView
{
    _screenBackView = [[SidebarView alloc]init];
    [self.view addSubview:_screenBackView];
    _screenBackView.hidden = YES;
    _screenBackView.backgroundColor = RGBColorAlpha(0, 0, 0, 0.4);
    [_screenBackView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(64, 0, 0, 0));
        
    }];
    [_screenBackView loadViewForData:_c_dataArray];
}


#pragma mark -- 类型弹出框
#define pickerViewH 160
#define clearButtonH 35
#define doneButtonH  USERDEFINED_TABBAR_H
//类型弹出框
-(void)setUIForTanChuPickerView
{
    CGFloat buttonW = 120;
    CGFloat jianGeW = 30;
    _tanchuView.frame = CGRectMake(0, SCREEN_H, SCREEN_W, clearButtonH+doneButtonH+pickerViewH);
    _tanchuView.backgroundColor = Line_color;
    _clearButton.frame = CGRectMake(jianGeW, 0, buttonW, clearButtonH);
    [_clearButton setTitle:@"清除" forState:UIControlStateNormal];
    [_clearButton setTitleColor:ShenZi_Color forState:UIControlStateNormal];
    _clearButton.titleLabel.font = [UIFont systemFontOfSize:14.0];
    //    _clearButton.backgroundColor = Line_color;
    _clearButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    _doneButton.frame = CGRectMake(SCREEN_W-jianGeW-buttonW, 0, buttonW, clearButtonH);
    [_doneButton setTitle:@"完成" forState:UIControlStateNormal];
    [_doneButton setTitleColor:ShenZi_Color forState:UIControlStateNormal];
    _doneButton.titleLabel.font = [UIFont systemFontOfSize:14.0];
    //    _doneButton.backgroundColor = Line_color;
    //使文字靠右
    _doneButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    _tanChuPickerView.frame = CGRectMake(0, clearButtonH, SCREEN_W, pickerViewH);
    _tanChuPickerView.backgroundColor = [UIColor whiteColor];
    _tanChuPickerView.delegate = self;
    _tanChuPickerView.dataSource = self;
    [_tanChuPickerView selectRow:0 inComponent:0 animated:YES];
    
    
}
#pragma mark --- 预提交
-(void)loadUIForYTJ
{
    _isMTM = YES;
    CGFloat viewH = SCREEN_H-USERDEFINED_TABBAR_H;
    CGFloat jianGeW = 30;
    CGFloat jianGeH = 30;
    CGFloat imageW = 561;
    CGFloat imageH = 389;
    _YTJBackView.hidden = YES;
    _YTJBackView.frame = CGRectMake(0, 0, SCREEN_W, viewH);
    _YTJBackView.backgroundColor = RGBColorAlpha(44, 44, 44, 0.6);
    [_YTJBackView addSubview:_YTJView];
    _YTJView.frame = CGRectMake((SCREEN_W-imageW)/2.0-jianGeW, (viewH-imageH)/2.0-jianGeH*3/2,  imageW+jianGeW*2, imageH+jianGeH*3);
    _YTJImage.frame = CGRectMake(jianGeW, jianGeH, imageW, imageH);
    _YTJImage.image = [UIImage imageNamed:@"ytj_back"];
    _YTJImage.userInteractionEnabled = YES;
    //给View加圆角和阴影
    CALayer *layer = [CALayer layer];
    layer.frame = CGRectMake(0, 0, imageW+jianGeW*2, imageH+jianGeH*3);
    layer.backgroundColor = [UIColor whiteColor].CGColor;
    layer.shadowOffset = CGSizeMake(0, 0);
    layer.shadowColor =RGBColor(205, 205, 205).CGColor;
    layer.shadowOpacity = 0.4;
    layer.cornerRadius = 8.0;
    [_YTJView.layer addSublayer:layer];
    [_YTJView bringSubviewToFront:_YTJImage];
    [_YTJView setYuanJiaoForRadius:8.0 andMasks:NO];
    CGFloat buttonW = 80;
    CGFloat buttonH = buttonW;
    _matchingButton.frame = CGRectMake(_YTJView.frame.size.width-jianGeW*2-buttonW, _YTJImage.frame.origin.y+_YTJImage.frame.size.height-buttonH/2.0-10, buttonW, buttonH);
    
    [_YTJView bringSubviewToFront:_matchingButton];
    [_matchingButton setYuanJiaoForRadius:8.0 andMasks:NO];
    viewH = buttonH+20;
    _liningChooseView.frame = CGRectMake(_YTJView.frame.size.width-jianGeW*2-buttonW, _YTJImage.frame.origin.y, buttonW, viewH);
    _liningChooseView.backgroundColor = [UIColor clearColor];
    [_YTJView bringSubviewToFront:_liningChooseView];
    _YTJ_lButton.frame = CGRectMake(0, 0, buttonW, buttonH);
    [_YTJ_lButton setBackgroundImage:[UIImage imageNamed:@"ytj_mianLiao"] forState:UIControlStateNormal];
    _YTJ_lButton.lineBreakMode = NSLineBreakByWordWrapping;//使可以换行
    [_YTJ_lButton setTitle:@"MTM\n面料" forState:UIControlStateNormal];
    [_YTJ_lButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    _YTJ_lButton.titleLabel.textAlignment = NSTextAlignmentCenter;
    _YTJ_lLabel.text = @"点击切换面料";
    _YTJ_lLabel.textColor = QianZi_color;
    _YTJ_lLabel.font = [UIFont systemFontOfSize:11];;
    _YTJ_lLabel.textAlignment = NSTextAlignmentCenter;
    _YTJ_lLabel.frame = CGRectMake(0, buttonH, buttonW, 20);
    //默认View
    CGFloat d_imageW = 118;
    CGFloat d_imageH = 112;
    jianGeW = 80;
    jianGeH = jianGeW;
    CGFloat d_viewW = imageW-jianGeW*2;
    CGFloat d_viewH = imageH-jianGeH*2;
    _defaultView.frame = CGRectMake(jianGeW, jianGeH, d_viewW, d_viewH);
    _YTJ_dImage.frame = CGRectMake((d_viewW-d_imageW)/2.0, (d_viewH-d_imageH)/2.0-20, d_imageW, d_imageH);
    _YTJ_dImage.image = [UIImage imageNamed:@"ytj_default"];
    _YTJ_dLabel.text = @"请单击匹配进行预提交操作";
    _YTJ_dLabel.textColor = QianZi_color;
    _YTJ_dLabel.font = [UIFont systemFontOfSize:12];
    _YTJ_dLabel.textAlignment = NSTextAlignmentCenter;
    _YTJ_dLabel.textAlignment = NSTextAlignmentCenter;
    _YTJ_dLabel.frame = CGRectMake(0, d_imageH+_YTJ_dImage.frame.origin.y, d_viewW, 20);
    [_YTJImage addSubview:_defaultView];
    _defaultView.hidden = NO;
    _YTJScrollView.hidden = YES;
    jianGeW = 70;
    jianGeH = jianGeW;
    CGFloat s_viewW = imageW-jianGeW*2+20;
    CGFloat s_viewH = imageH-jianGeH*2+40;
    _YTJScrollView.frame = CGRectMake(jianGeW, jianGeH, s_viewW, s_viewH);
    [_YTJImage addSubview:_YTJScrollView];
    CGFloat s_jianGeW = 30;
    
    CGFloat so_viewW = s_viewW-s_jianGeW*2;
    CGFloat so_viewH = 80;
    _YTJ_sOptionView.frame = CGRectMake(s_jianGeW, 0, so_viewW, so_viewH);
    _YTJ_sOptionView.hidden = YES;
    [self loadYTJS_OptionView];
    _YTJ_sNewsView.frame = CGRectMake(0, so_viewH, s_viewW, s_viewH-so_viewH);
    
    CGFloat s_imageW = 68;
    CGFloat s_imageH = s_imageW;
    CGFloat s_jianGeH = s_imageH/2.0;
    _YTJ_sHeadImage.frame = CGRectMake((s_viewW-s_imageW)/2.0, 0, s_imageW, s_imageH);
    _YTJ_sHeadImage.image = [UIImage imageNamed:@"chenggong"];
    _YTJ_sHeadLabel.text = @"提交成功";
    _YTJ_sHeadLabel.textColor = RGBColorAlpha(115, 206, 15, 1);
    _YTJ_sHeadLabel.font = Cell_Medium_Font;
    [_YTJ_sHeadLabel sizeToFit];
    _YTJ_sHeadLabel.frame = CGRectMake((s_viewW-_YTJ_sHeadLabel.frame.size.width)/2.0, _YTJ_sHeadImage.frame.origin.y+_YTJ_sHeadImage.frame.size.height, _YTJ_sHeadLabel.frame.size.width, Nomal_Label_H);
    _YTJ_sNewsBackImage.frame = CGRectMake(0, s_jianGeH, s_viewW, s_viewH-jianGeH);
    _YTJ_sNewsBackImage.image = [UIImage imageNamed:@"ytj_s_back"];
    _YTJ_sNewsBackImage.userInteractionEnabled = YES;
    _YTJ_sLineView.frame  =CGRectMake(20, _YTJ_sHeadLabel.frame.size.height+_YTJ_sHeadLabel.frame.origin.y+5, s_viewW-40, 2);
    _YTJ_sLineView.backgroundColor  =Line_color;
    _YTJ_sContentScrollView.frame = CGRectMake(20, _YTJ_sLineView.frame.size.height+_YTJ_sLineView.frame.origin.y, s_viewW-40, s_viewH-(_YTJ_sLineView.frame.size.height+_YTJ_sLineView.frame.origin.y+5));
    
    [self loadYTJS_NewsView];
    [self setUIForTanChuPickerView];
    
}

#define  Text_Tag 900000
#define OptionText_Tag 901000
-(void)loadYTJS_OptionView
{
    for (UIView * view in _YTJ_sOptionView.subviews) {
        [view removeFromSuperview];
    }
    NSArray * nameArr = [NSArray arrayWithObjects:@"条格",@"",@"幅宽",@"条格宽度" ,nil];
    NSArray * unitArr = [NSArray arrayWithObjects:@"",@"",@"m",@"cm" ,nil];
    CGFloat jianGeW = 40;
    CGFloat viewW = (_YTJ_sOptionView.frame.size.width-jianGeW)/2.0;
    CGFloat viewH = 35;
    for (int i=0; i<4; i++) {
        int k = i/2;
        int j = i%2;
        UIView * view = [[UIView alloc]initWithFrame:CGRectMake((viewW+jianGeW)*j, viewH*k, viewW, viewH)];
        UILabel * label = [[UILabel alloc]init];
        label.text =[NSString stringWithFormat:@"%@：",[nameArr objectAtIndex:i]];
        label.textColor = ZhongZi_Color;
        label.font = Cell_Little_Font;
        [label sizeToFit];
        label.frame = CGRectMake(0, (viewH-Nomal_Label_H)/2.0, label.frame.size.width, Nomal_Label_H);
        [view addSubview:label];
        UIView * lineView = [[UIView alloc]initWithFrame:CGRectMake(0, viewH-1, viewW, 1)];
        lineView.backgroundColor = Line_color;
        [view addSubview:lineView];
        if ([[unitArr objectAtIndex:i] isEqualToString:@""]) {
            CGFloat imageW = 14;
            CGFloat imageH = imageW;
            UIImageView * image = [[UIImageView alloc]initWithFrame:CGRectMake((viewW-imageW), (viewH-imageH)/2.0, imageW, imageH)];
            image.image = [UIImage imageNamed:@"ytj_xiaBiao"];
            [view addSubview:image];
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(label.frame.origin.x+label.frame.size.width+5, (viewH-Nomal_Label_H)/2.0, viewW-(label.frame.origin.x+label.frame.size.width+5)-image.frame.size.width-5, Nomal_Label_H)];
            text.textColor = ShenZi_Color;
            text.enabled = NO;
            text.font = Cell_Big_Font;
            text.tag = OptionText_Tag;
            [view addSubview:text];
            UIButton * button = [[UIButton alloc]initWithFrame:CGRectMake(label.frame.origin.x+label.frame.size.width+5, (viewH-Nomal_Label_H)/2.0, viewW-(label.frame.origin.x+label.frame.size.width+5), Nomal_Label_H)];
            [button addTarget:self action:@selector(optionButtonFunc:) forControlEvents:UIControlEventTouchUpInside];
            [view addSubview:button];
        }else{
            UILabel * unitLabel = [[UILabel alloc]init];
            unitLabel.text = [unitArr objectAtIndex:i];
            unitLabel.textColor = QianZi_color;
            unitLabel.font = Cell_Little_Font;
            [unitLabel sizeToFit];
            unitLabel.frame = CGRectMake(viewW-unitLabel.frame.size.width, (viewH-Nomal_Label_H)/2.0, unitLabel.frame.size.width, Nomal_Label_H);
            [view addSubview:unitLabel];
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(label.frame.origin.x+label.frame.size.width+5, (viewH-Nomal_Label_H)/2.0, viewW-(label.frame.origin.x+label.frame.size.width+5)-unitLabel.frame.size.width-5, Nomal_Label_H)];
            text.tag = Text_Tag+i;
            text.returnKeyType = UIReturnKeyNext;
            text.delegate = self;
            text.textColor = ShenZi_Color;
            text.font = Cell_Big_Font;
            [view addSubview:text];
        }
        
        
        if (i==0) {
            i++;
        }
        
        [_YTJ_sOptionView addSubview:view];
    }
}
#define YTJ_NewsView_Tag 904000
-(void)loadYTJS_NewsView
{
    for (UIView * view in _YTJ_sContentScrollView.subviews) {
        [view removeFromSuperview];
    }
    NSArray * nameArr = [NSArray arrayWithObjects:@"订单号",@"单耗",@"衬衣成衣尺寸" ,nil];
    NSArray * valueArr = [NSArray arrayWithObjects:@"TYUH789909",@"785.984cm 87867inch",@"左袖口：29.9 后衣长：78cm 时尚风 左袖口：29.9 后衣长：78cm 左袖口：29.9 后衣长：78cm " ,nil];
    CGFloat viewW = _YTJ_sContentScrollView.frame.size.width;
    CGFloat viewH = 30;
    for (int i=0; i<nameArr.count; i++) {
        UIView * tmpView = [_YTJ_sContentScrollView viewWithTag:YTJ_NewsView_Tag+i-1];
        UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, tmpView.frame.origin.y+tmpView.frame.size.height, viewW, viewH)];
        view.tag = YTJ_NewsView_Tag+i;
        [_YTJ_sContentScrollView addSubview:view];
        UILabel * label = [[UILabel alloc]init];
        label.text  =[nameArr objectAtIndex:i];
        label.textColor = QianZi_color;
        label.font = Cell_Little_Font;
        [label sizeToFit];
        label.frame = CGRectMake(0, (viewH-Nomal_Label_H)/2.0, label.frame.size.width, Nomal_Label_H);
        [view addSubview:label];
        UILabel * content = [[UILabel alloc]init];
        content.frame = CGRectMake(label.frame.origin.x+label.frame.size.width+20, (viewH-Nomal_Label_H)/2.0, viewW-(label.frame.origin.x+label.frame.size.width+20), Nomal_Label_H);
        content.text = [valueArr objectAtIndex:i];
        content.textColor = ZhongZi_Color;
        content.font = Cell_Medium_Font;
        content.numberOfLines = 0;
        content.textAlignment = NSTextAlignmentRight;
        [content sizeToFit];
        content.frame = CGRectMake(label.frame.origin.x+label.frame.size.width+20, (viewH-Nomal_Label_H)/2.0, viewW-(label.frame.origin.x+label.frame.size.width+20), content.frame.size.height+5);
        view.frame = CGRectMake(0, tmpView.frame.origin.y+tmpView.frame.size.height, viewW, content.frame.origin.y+content.frame.size.height);
        
        [view addSubview:content];
        [_YTJ_sContentScrollView addSubview:view];
    }
    UIView * lastView = [_YTJ_sContentScrollView viewWithTag:YTJ_NewsView_Tag+nameArr.count-1];
    _YTJ_sContentScrollView.contentSize = CGSizeMake(_YTJ_sContentScrollView.frame.size.width, lastView.frame.origin.y+lastView.frame.size.height+110);
    
}
#pragma mark --- 标签颜色选择
-(void)loadUIForColorView
{
    CGFloat viewH = SCREEN_H-USERDEFINED_TABBAR_H;
    CGFloat jianGeW = 30;
    CGFloat jianGeH = 30;
    CGFloat imageW = 561;
    CGFloat imageH = 389;
    _colorBackView.hidden = YES;
    
    _colorBackView.frame = CGRectMake(0, 20, SCREEN_W, viewH);
    _colorBackView.backgroundColor = RGBColorAlpha(44, 44, 44, 0.6);
    [_colorBackView addSubview:_colorView];
    _colorView.frame = CGRectMake((SCREEN_W-imageW)/2.0-jianGeW, (viewH-imageH)/2.0-jianGeH*3/2,  imageW+jianGeW*2, imageH+jianGeH*3);
    _colorImage.frame = CGRectMake(jianGeW, jianGeH, imageW, imageH);
    _colorImage.image = [UIImage imageNamed:@"colorback"];
    _colorImage.userInteractionEnabled = YES;
    //给View加圆角和阴影
    CALayer *layer = [CALayer layer];
    layer.frame = CGRectMake(0, 0, imageW+jianGeW*2, imageH+jianGeH*3);
    layer.backgroundColor = [UIColor whiteColor].CGColor;
    layer.shadowOffset = CGSizeMake(0, 0);
    layer.shadowColor =RGBColor(205, 205, 205).CGColor;
    layer.shadowOpacity = 0.4;
    layer.cornerRadius = 8.0;
    [_colorView.layer addSublayer:layer];
    [_colorView bringSubviewToFront:_colorImage];
    CGFloat buttonW = 60;
    CGFloat buttonH = buttonW;
    _c_saveButton.frame = CGRectMake(_colorView.frame.size.width-jianGeW*2-buttonW, _colorImage.frame.origin.y+_colorImage.frame.size.height-buttonH/2.0-10, buttonW, buttonH);
    CALayer *layer2 = [CALayer layer];
    layer2.frame = CGRectMake(_colorView.frame.size.width-jianGeW*2-buttonW, _colorImage.frame.origin.y+_colorImage.frame.size.height-buttonH/2.0-10, buttonW, buttonH);
    layer2.backgroundColor = [UIColor whiteColor].CGColor;
    layer2.shadowOffset = CGSizeMake(0, 0);
    layer2.shadowColor =RGBColor(205, 205, 205).CGColor;
    layer2.shadowOpacity = 0.4;
    layer2.cornerRadius = 8.0;
    [_colorView.layer addSublayer:layer2];
    [_c_saveButton setTitle:@"保存" forState:UIControlStateNormal];
    [_c_saveButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _c_saveButton.backgroundColor = ZhuBack_color;
    [_colorView bringSubviewToFront:_c_saveButton];
    [_c_saveButton setYuanJiaoForRadius:8.0 andMasks:NO];
    [_colorView setYuanJiaoForRadius:8.0 andMasks:NO];
    
    CGFloat s_jianGeW = 50;
    CGFloat s_jianGeH = 100;
    CGFloat s_viewW = imageW-s_jianGeW*2+20;
    CGFloat s_viewH = 160;
    _c_scrollView.frame = CGRectMake(s_jianGeW, s_jianGeH, s_viewW,s_viewH);
    _c_scrollNameLabel.text = @"颜色选择：";
    _c_scrollNameLabel.textColor = ShenZi_Color;
    _c_scrollNameLabel.font = Cell_Medium_Font;
    [_c_scrollNameLabel sizeToFit];
    _c_scrollNameLabel.frame = CGRectMake(0, 0, _c_scrollNameLabel.frame.size.width, Nomal_Label_H);
    _c_scroll.frame  =CGRectMake(0, _c_scrollNameLabel.frame.origin.y+_c_scrollNameLabel.frame.size.height+10, s_viewW, s_viewH-(_c_scrollNameLabel.frame.origin.y+_c_scrollNameLabel.frame.size.height+5));
    _c_scroll.showsVerticalScrollIndicator = NO;
    _c_scroll.showsHorizontalScrollIndicator = NO;
    [self loadColorScrollView];
    s_viewH = 40;
    _c_textView.frame  =CGRectMake(s_jianGeW, _c_scrollView.frame.origin.y+_c_scrollView.frame.size.height+10, s_viewW, s_viewH);
    _c_textNameLabel.text = @"内容输入：";
    _c_textNameLabel.textColor = ShenZi_Color;
    _c_textNameLabel.font = Cell_Medium_Font;
    [_c_textNameLabel sizeToFit];
    _c_textNameLabel.frame = CGRectMake(0, 5, _c_textNameLabel.frame.size.width, 30);
    _c_text.frame = CGRectMake(_c_textNameLabel.frame.origin.x+_c_textNameLabel.frame.size.width+5, 5, s_viewW-(_c_textNameLabel.frame.origin.x+_c_textNameLabel.frame.size.width+5)-jianGeW, 30);
    _c_text.textColor = ShenZi_Color;
    _c_text.text = _model.tagName;
    _c_text.font = Cell_Big_Font;
    _c_lineView.frame = CGRectMake(0, s_viewH-1, s_viewW, 1);
    _c_lineView.backgroundColor = Line_color;
    [_colorImage addSubview:_c_scrollView];
    [_colorImage addSubview:_c_textView];
}

-(void)loadColorScrollView
{
    
    CGFloat jianGeW = 8;
    CGFloat jianGeH = 8;
    CGFloat buttonH = (_c_scroll.frame.size.height-jianGeH)/2.0;
    CGFloat buttonW = buttonH;
    
    for (UIView * view in _c_scroll.subviews) {
        [view removeFromSuperview];
    }
    for (int i=0; i<_colorArray.count; i++) {
        ShoppingColorModel * model = [_colorArray objectAtIndex:i];
        int j = i/2;
        int k = i%2;
        UIImageView * image = [[UIImageView alloc]initWithFrame:CGRectMake((jianGeW+buttonW)*j, (jianGeH+buttonH)*k, buttonW, buttonH)];
        
        image.userInteractionEnabled = YES;
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(colorChoose:)];
        image.tag = Image_Tag+i;
        [image addGestureRecognizer:tap];
        
        image.userInteractionEnabled = YES;
        UIImageView * l_image =[[UIImageView alloc]initWithFrame:CGRectMake(0, jianGeH, buttonW-jianGeW, buttonH-jianGeH)];
        [l_image setYuanJiaoForRadius:5.0 andMasks:YES];
        l_image.userInteractionEnabled = YES;
        l_image.backgroundColor = model.color;
        CGFloat w_buttonW = 60;
        CGFloat w_buttonH = w_buttonW/42.*44;
        UIImageView * w_image = [[UIImageView alloc]initWithFrame:CGRectMake(image.frame.size.width-w_buttonW, 0, w_buttonW, w_buttonH)];
        if (model.isChoose) {
            w_image.image = [UIImage imageNamed:@"colorXuan"];
        }else{
            w_image.image = [UIImage imageNamed:@""];
        }
        
        [image addSubview:l_image];
        [image addSubview:w_image];
        [_c_scroll addSubview:image];
    }
    int count = (int)self.colorArray.count/2;
    if (self.colorArray.count%2 == 1) {
        count++;
    }
    CGFloat scrollW = count*(jianGeW+buttonW);
    _c_scroll.contentSize = CGSizeMake(scrollW, _c_scroll.frame.size.height);
}

#pragma mark - 竖屏适配
-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    CGFloat viewW = SCREEN_W/2.0+120;
    CGFloat jianGeW = SCREEN_W-viewW;
    //侧边栏
    
    jianGeW = 80;
    CGFloat searchViewH = 40;
    CGFloat searchViewW = SCREEN_W-jianGeW*2;
    CGFloat downViewH = 60;
    _searchView.frame = CGRectMake(jianGeW, TOPNAVIGATIONBAR_H+10, searchViewW, searchViewH);
    _tableView.frame = CGRectMake(0, TOPNAVIGATIONBAR_H+20+searchViewH, SCREEN_W, SCREEN_H-USERDEFINED_TABBAR_H-downViewH-(TOPNAVIGATIONBAR_H+20+searchViewH));
    [_tableView reloadData];
    
    //底部
    [self setUIForDownView];
    
    //空白页
    [self loadKongPage];
    //弹出picker
    _tanchuView.frame = CGRectMake(0, SCREEN_H, SCREEN_W, clearButtonH+doneButtonH+pickerViewH);
    [_screenBackView.collectionView reloadData];
    //预提交
    CGFloat viewH = SCREEN_H-USERDEFINED_TABBAR_H;
    jianGeW = 30;
    CGFloat jianGeH = 30;
    CGFloat imageW = 561;
    CGFloat imageH = 389;
    _YTJBackView.frame = CGRectMake(0, 0, SCREEN_W, viewH);
    _YTJView.frame = CGRectMake((SCREEN_W-imageW)/2.0-jianGeW, (viewH-imageH)/2.0-jianGeH*3/2,  imageW+jianGeW*2, imageH+jianGeH*3);
    //颜色选择
    _colorBackView.frame = CGRectMake(0, 20, SCREEN_W, viewH);
    _colorView.frame = CGRectMake((SCREEN_W-imageW)/2.0-jianGeW, (viewH-imageH)/2.0-jianGeH*3/2,  imageW+jianGeW*2, imageH+jianGeH*3);
    //弹出picker
    [self setUIForTanChuPickerView];
}
#pragma mark --- 购物车列表布局
-(void)loadUI
{
    CGFloat jianGeW = 80;
    CGFloat searchViewH = 40;
    CGFloat searchViewW = SCREEN_W-jianGeW*2;
    CGFloat imageW = 20;
    CGFloat imageH = imageW;
    CGFloat downViewH = 60;
    _searchView.frame = CGRectMake(jianGeW, TOPNAVIGATIONBAR_H+10, searchViewW, searchViewH);
    _tableView.frame = CGRectMake(0, TOPNAVIGATIONBAR_H+20+searchViewH, SCREEN_W, SCREEN_H-USERDEFINED_TABBAR_H-downViewH-(TOPNAVIGATIONBAR_H+20+searchViewH));
    [_searchView setYuanJiaoForRadius:10.0 andMasks:NO];
//    _s_text.frame = CGRectMake(jianGeW, (searchViewH-40)/2.0, searchViewW-jianGeW*2, 40);
    [_s_text mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(jianGeW));
        make.right.equalTo(@(-jianGeW));
        make.centerY.equalTo(_searchView);
        make.height.equalTo(@40);
    }];
    _s_text.textAlignment = NSTextAlignmentCenter;
    _s_text.placeholder = @"请输入订单号/客户单号/面料号/客户名/备注等关键词";
    _s_text.textColor = ShenZi_Color;
    _s_text.font = Cell_Medium_Font;
    _s_text.tag = 910000;
    _s_text.delegate = self;
    _s_text.returnKeyType = UIReturnKeySearch;
//    _s_image.frame = CGRectMake(searchViewW-30-imageW, (searchViewH-imageH)/2.0, imageW, imageH);
    [_s_image mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_searchView).offset(-30);
        make.width.equalTo(@(imageW));
        make.height.equalTo(@(imageH));
        make.centerY.equalTo(_searchView);
    }];
    _s_image.image = [UIImage imageNamed:@"search2"];
}
-(void)setUIForDownView
{
    CGFloat jianGeW = 25;
    CGFloat buttonW = 20;
    CGFloat buttonH = buttonW;
    CGFloat d_buttonW = 80;
    CGFloat d_buttonH = 30;
    CGFloat downViewH = 60;
    _downView.frame = CGRectMake(-1, SCREEN_H-USERDEFINED_TABBAR_H-downViewH, SCREEN_W+2, downViewH);
    [_downView setBianKuangAndColor:RGBColor(235, 235, 235)];
    _d_chooseButton.frame = CGRectMake(jianGeW+1, (downViewH-buttonH)/2.0, buttonW, buttonH);
    [_d_chooseButton setImage:[UIImage imageNamed:@"s_noChoose"] forState:UIControlStateNormal];
    _d_delegateButton.titleLabel.font = Cell_Big_Font;
    _d_delegateButton.frame = CGRectMake(_d_chooseButton.frame.origin.x+_d_chooseButton.frame.size.width+jianGeW, (downViewH-d_buttonH)/2.0, d_buttonW, d_buttonH);
    [_d_delegateButton setTitle:@"删除订单" forState:UIControlStateNormal];
    [_d_delegateButton setTitleColor:ZhongZi_Color forState:UIControlStateNormal];
    NSString * str = @"198";
    
    NSString * needStr = [NSString stringWithFormat:@"已选择 %@ 件商品",str];
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:needStr];
    
    // 设置字体和设置字体的范围
    [attrStr addAttribute:NSFontAttributeName
                    value:Cell_Little_Font
                    range:NSMakeRange(0, needStr.length)];
    // 添加文字颜色
    [attrStr addAttribute:NSForegroundColorAttributeName
                    value:QianZi_color
                    range:NSMakeRange(0, needStr.length)];
    // 添加文字颜色
    [attrStr addAttribute:NSForegroundColorAttributeName
                    value:RGBColorAlpha(227, 65, 85, 1)
                    range:NSMakeRange(4, str.length)];
    // 设置字体和设置字体的范围
    [attrStr addAttribute:NSFontAttributeName
                    value:[UIFont systemFontOfSize:15.0f]
                    range:NSMakeRange(4, str.length)];
    _d_chooseLabel.attributedText = attrStr;
    
    [_d_chooseLabel sizeToFit];
    _d_chooseLabel.frame = CGRectMake(_d_delegateButton.frame.origin.x+_d_delegateButton.frame.size.width+jianGeW*2, (downViewH-Nomal_Label_H)/2.0, _d_chooseLabel.frame.size.width, Nomal_Label_H);
    buttonW = 80;
    [_d_jiesuanButton setTitle:@"去结算" forState:UIControlStateNormal];
    [_d_jiesuanButton setTitleColor:RGBColorAlpha(208, 63, 81, 1) forState:UIControlStateNormal];
    _d_jiesuanButton.backgroundColor = RGBColorAlpha(44, 44, 44, 1);
    _d_jiesuanButton.titleLabel.font = Cell_Big_Font;
    [_d_jiesuanButton.titleLabel sizeToFit];
    [_d_jiesuanButton sizeToFit];
    _d_jiesuanButton.frame = CGRectMake(SCREEN_W-buttonW+1, 0, buttonW, downViewH);
    [_d_tuoGuanButton setTitle:@"托管" forState:UIControlStateNormal];
    [_d_tuoGuanButton setTitleColor:ZhongZi_Color forState:UIControlStateNormal];
    _d_tuoGuanButton.backgroundColor = RGBColorAlpha(225, 225, 225, 1);
    _d_tuoGuanButton.titleLabel.font = Cell_Big_Font;
    [_d_tuoGuanButton.titleLabel sizeToFit];
    [_d_tuoGuanButton sizeToFit];
    _d_tuoGuanButton.frame = CGRectMake(SCREEN_W-buttonW*2+1, 0, buttonW, downViewH);
    
    _d_countNameLabel.text = @"总价(不包含运费)：";
    _d_countNameLabel.textColor = QianZi_color;
    _d_countNameLabel.font = Cell_Little_Font;
    [_d_countNameLabel sizeToFit];
    _d_countValueLabel.text = [NSString stringWithFormat:@"¥798.89"];
    _d_countValueLabel.textColor = RGBColorAlpha(255, 69, 91, 1);
    _d_countValueLabel.font = Cell_Medium_Font;
    [_d_countValueLabel sizeToFit];
    CGFloat labelH = 25;
    _d_countValueLabel.frame = CGRectMake(SCREEN_W-buttonW*2+1-_d_countValueLabel.frame.size.width-30, (downViewH-labelH*2)/2.0, _d_countValueLabel.frame.size.width+30, labelH);
    _d_countNameLabel.frame = CGRectMake(SCREEN_W-buttonW*2+1-_d_countValueLabel.frame.size.width-_d_countNameLabel.frame.size.width, _d_countValueLabel.frame.origin.y, _d_countNameLabel.frame.size.width, labelH);
    
    _d_saveNameLabel.text = @"已节省：";
    _d_saveNameLabel.textColor = QianZi_color;
    _d_saveNameLabel.font = Cell_Little_Font;
    [_d_saveNameLabel sizeToFit];
    _d_saveValueLabel.text = [NSString stringWithFormat:@"¥0.89"];
    _d_saveValueLabel.textColor = RGBColorAlpha(255, 69, 91, 1);
    _d_saveValueLabel.font = Cell_Medium_Font;
    [_d_saveValueLabel sizeToFit];
    
    _d_saveValueLabel.frame = CGRectMake(SCREEN_W-buttonW*2+1-_d_saveValueLabel.frame.size.width-30, _d_countNameLabel.frame.origin.y+_d_countNameLabel.frame.size.height, _d_saveValueLabel.frame.size.width+30, labelH);
    _d_saveNameLabel.frame = CGRectMake(SCREEN_W-buttonW*2+1-_d_saveValueLabel.frame.size.width-_d_saveNameLabel.frame.size.width, _d_saveValueLabel.frame.origin.y, _d_saveNameLabel.frame.size.width, labelH);
    
}
#pragma mark - 数据处理
//获取选中的标签
- (void)getStrFromArray
{
    NSString * str = @"";
    _nameStr = @"";
    _idStr = @"";
    for (int i=0; i<_nameArray.count; i++) {
        ShoppingCollectionModel * model = [_nameArray objectAtIndex:i];
        if (model.is_Choose) {
            str = [NSString stringWithFormat:@"%@   %@",str,model.title];
            _nameStr =[NSString stringWithFormat:@"%@,%@",_nameStr,model.title];
            _idStr =[NSString stringWithFormat:@"%@,%@",_idStr,model._id];
        }
    }
    if (str.length>3) {
        str = [str substringFromIndex:3];
    }
    if (_nameStr.length>0) {
        _nameStr = [_nameStr substringFromIndex:1];
    }
    if (_idStr.length>0) {
        _idStr = [_idStr substringFromIndex:1];
    }
    
}
-(void)uploadC_DataArray
{
    
    NSArray * idArray = [_idStr componentsSeparatedByString:@","];
    
    for (int i=0; i<_c_dataArray.count; i++) {
        ShoppingCollectionModel * model = [_c_dataArray objectAtIndex:i];
        NSArray *needArray =[handleData arrayWithClass:[ShoppingCollectionModel class] andDataArray:model.childArr];
        model.childArr = [NSMutableArray arrayWithArray:needArray];
        if (idArray.count >0) {
            for (int j = 0; j<model.childArr.count; j++) {
                ShoppingCollectionModel * tmpModel = [model.childArr objectAtIndex:j];
                BOOL isbool = [idArray containsObject:GlobalHandleValue(tmpModel._id)];//判断数组是否包含某个元素
                tmpModel.is_Choose = isbool;
                [model.childArr replaceObjectAtIndex:j withObject:tmpModel];
                [self.nameArray addObject:tmpModel];
            }
        }
        
        [_c_dataArray replaceObjectAtIndex:i withObject:model];
    }
    
    
}
-(void)loadKongPage
{
    [_kongPage removeFromSuperview];
    if (self.dataArray.count == 0) {
        layoutViews(^{
            _kongPage = [PublicBlankView sharedLittleInstanceWithViewController:_tableView andImage:@"kong" andTitle:@"购物车里空空如也！" andButtonName:@"赶紧去定制您的专属服饰！>>" andCGFloat:CGRectMake(0, 0, SCREEN_W, SCREEN_H-(_tableView.frame.origin.y)-USERDEFINED_TABBAR_H) andPointY:50];
        }, ^{
            _kongPage = [PublicBlankView sharedLittleInstanceWithViewController:_tableView andImage:@"kong" andTitle:@"购物车里空空如也！" andButtonName:@"赶紧去定制您的专属服饰！>>" andCGFloat:CGRectMake(0, 0, SCREEN_W, SCREEN_H-(_tableView.frame.origin.y)-USERDEFINED_TABBAR_H) andPointY:80];
        });
        _kongPage.backColor = RGBColorAlpha(240, 240, 240, 1);
    }
}


#pragma mark -- pickerview delegate & pickerview datasource
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{
    return 1;
    
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    
    return _typeArr.count;
    
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
    UILabel* pickerLabel = (UILabel*)view;
    if (!pickerLabel){
        pickerLabel = [[UILabel alloc] init];
        // Setup label properties - frame, font, colors etc
        //adjustsFontSizeToFitWidth property to YES
        pickerLabel.adjustsFontSizeToFitWidth = YES;
        [pickerLabel setTextAlignment:NSTextAlignmentCenter];
        [pickerLabel setBackgroundColor:[UIColor clearColor]];
        [pickerLabel setFont:[UIFont systemFontOfSize:14]];
    }
    // Fill the label text here
    pickerLabel.text=[self pickerView:pickerView titleForRow:row forComponent:component];
    return pickerLabel;
}

- (NSString *)pickerView:(UIPickerView *)pickerView
             titleForRow:(NSInteger)row
            forComponent:(NSInteger)component
{
    TypeModel* model = [_typeArr objectAtIndex:row];
    //    UITextField * text = [_YTJ_sOptionView viewWithTag:OptionText_Tag];
    //    text.text = GlobalHandleValue(model.name);
    return model.name;
}
-(NSString *)selectTitleWith:(NSInteger)row andDataArr:(NSArray *)arr{
    
    TypeModel* model = [_typeArr objectAtIndex:row];
    
    return model.name;
    
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    TypeModel* model = [_typeArr objectAtIndex:row];
    UITextField * text = [_YTJ_sOptionView viewWithTag:OptionText_Tag];
    text.text = GlobalHandleValue(model.name);
}

#pragma mark - textFeildDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField == _s_text) {//搜索text
        
    }else{
        int index = (int)textField.tag-Text_Tag;
        if (textField.becomeFirstResponder) {
            UITextField * text = [_YTJ_sOptionView viewWithTag:Text_Tag+index+1];
            [textField resignFirstResponder];
            [text becomeFirstResponder];
        }
    }
    
    return YES;
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    return YES;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

{
    
    return YES;
    
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    
}

-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    return YES;
}

#pragma mark -- tableViewDelegate and dataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //    return 10;
    return _dataArray.count;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

#define CellHeight 160
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return CellHeight;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    ShoppingCarModel * model = [_dataArray objectAtIndex:indexPath.row];
    //    ShoppingCarModel * model = [[ShoppingCarModel alloc]init];
    model.indexPath = indexPath;
    ShoppingCarTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ShoppingCarTableViewCell"];
    [cell setCellWithModel:model];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
}

#pragma mark - 随机色
-(UIColor *) randomColor
{
    CGFloat hue = ( arc4random() % 256 / 256.0 ); //0.0 to 1.0
    CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0,away from white
    CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; //0.5 to 1.0,away from black
    return [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
}
#pragma mark - 手势按钮方法
//pickerViewButton开始
- (IBAction)doneButton:(id)sender {
    [UIView animateWithDuration:0.37 animations:^{
        _tanchuView.frame = CGRectMake(0, SCREEN_H, SCREEN_W, clearButtonH+doneButtonH+pickerViewH);
        
    } completion:^(BOOL finished) {
        UITextField * text = [_YTJ_sOptionView viewWithTag:Text_Tag+2];
        [text becomeFirstResponder];
    }];
    
}

- (IBAction)clearButton:(id)sender {
    UITextField * text = [_YTJ_sOptionView viewWithTag:OptionText_Tag];
    text.text = @"";
    [UIView animateWithDuration:0.37 animations:^{
        _tanchuView.frame = CGRectMake(0, SCREEN_H, SCREEN_W, clearButtonH+doneButtonH+pickerViewH);
        
    } completion:^(BOOL finished) {
        
    }];
}
//pickerViewButton结束

// 颜色选择开始
-(void)colorChoose:(UITapGestureRecognizer*)tap
{
    
    _c_index = (int)tap.view.tag-Image_Tag;
    for (ShoppingColorModel * model in _colorArray) {
        model.isChoose = NO;
    }
    ShoppingColorModel * tmpmodel = [_colorArray objectAtIndex:_c_index];
    tmpmodel.isChoose = YES;
    [self loadColorScrollView];
}

- (IBAction)c_saveButton:(UIButton *)sender {
    ShoppingColorModel * model = [_colorArray objectAtIndex:_c_index];
    _model.tagName = _c_text.text;
    _model.tagColor = model.color;
    _colorBackView.hidden = YES;
    [_tableView reloadData];
}
- (IBAction)colorBackView:(UIButton *)sender {
    _colorBackView.hidden = YES;
}
// 颜色选择结束

// 底部按钮开始
- (IBAction)d_chooseButton:(UIButton *)sender {
    
    _isChoose = !_isChoose;
    if (_isChoose) {
        for (ShoppingCarModel * model in _dataArray) {
            model.is_Choose = YES;
        }
        [_d_chooseButton setImage:[UIImage imageNamed:@"s_choose"] forState:UIControlStateNormal];
    }else{
        for (ShoppingCarModel * model in _dataArray) {
            model.is_Choose = NO;
        }
        [_d_chooseButton setImage:[UIImage imageNamed:@"s_noChoose"] forState:UIControlStateNormal];
    }
    [_tableView reloadData];
}
- (IBAction)d_tuoGuanButton:(UIButton *)sender {
    _formulaView = [[ValuationFormulaView alloc]init];
    [self.view addSubview:_formulaView];
    _formulaView.backgroundColor = RGBColorAlpha(0, 0, 0, 0.4);
    [_formulaView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    
}

- (IBAction)d_jiesuanButton:(UIButton *)sender {
    
//    [self.view addSubview:self.shopView];
//    [self orderOfTheLeft:4];

   OrderProcessingViewController *vc = [[OrderProcessingViewController alloc] init];
    vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    vc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
    [self.navigationController.tabBarController presentViewController:vc animated:YES completion:nil];
    //UIApplication.sharedApplication.keyWindow.rootViewController
}

- (IBAction)d_delegateButton:(UIButton *)sender {
}
// 底部按钮结束


// 预提交开始
- (IBAction)YTJ_lButton:(UIButton *)sender {
    _isMTM = !_isMTM;
    if (_isMTM) {
        _YTJ_sOptionView.hidden = YES;
        [_YTJ_lButton setTitle:@"MTM\n面料" forState:UIControlStateNormal];
    }else{
        _YTJ_sOptionView.hidden = NO;
        [_YTJ_lButton setTitle:@"客供\n面料" forState:UIControlStateNormal];
    }
}
- (IBAction)YTJBackView:(UIButton *)sender {
    _YTJBackView.hidden = YES;
    [_matchingButton setImage:[UIImage imageNamed:@"ytj_noxuanzhong"] forState:UIControlStateNormal];
}

- (IBAction)matchingButton:(id)sender {
    [self loadYTJS_NewsView];
    [_matchingButton setImage:[UIImage imageNamed:@"ytj_xuanzhong"] forState:UIControlStateNormal];
    _defaultView.hidden = YES;
    _YTJScrollView.hidden = NO;
}
-(void)optionButtonFunc:(UIButton*)button
{
    for (int i=0; i<4; i++) {
        UITextField * text = [_YTJ_sOptionView viewWithTag:Text_Tag+i];
        [text resignFirstResponder];
    }
    
    [UIView animateWithDuration:0.37 animations:^{
        _tanchuView.frame = CGRectMake(0, SCREEN_H-doneButtonH-clearButtonH-pickerViewH, SCREEN_W, clearButtonH+doneButtonH+pickerViewH);
        
    } completion:^(BOOL finished) {
        
        
    }];
}


- (void)orderOfTheLeft:(int)num{
    
//    self.repeatNum = num;
//    //设置初始值
////    self.shopView.bottomWhiteView.numLabel.text = [NSString stringWithFormat:@"%d",num];
////    [self.mArray addObject:self.shopView.bottomWhiteView.numLabel];
//
//    self.timer = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(doAnimation) userInfo:nil repeats:YES];
}


- (void)doAnimation{
    
    //提交订单
//    self.repeatNum -=1;
//    CGRect lastFrame = self.shopView.bottomWhiteView.numLabel.frame;
//    UILabel *tempLabel = [self LabelWithNum:self.repeatNum WithFrame:CGRectMake(CGRectGetMinX(lastFrame), CGRectGetMinY(lastFrame), CGRectGetWidth(lastFrame), 0)];
//    [self.shopView.bottomWhiteView addSubview:tempLabel];
//    [UIView animateWithDuration:0. animations:^{
//
//        tempLabel.frame = CGRectMake(CGRectGetMinX(lastFrame), CGRectGetMinY(lastFrame), CGRectGetWidth(lastFrame), CGRectGetHeight(lastFrame));
//        if (self.repeatNum == -1) {
//#warning 添加改变的图片颜色
//            self.shopView.bottomWhiteView.circleVIew.image = [UIImage imageNamed:@""];
//        }
//    } completion:^(BOOL finished) {
//
//        [self removeAllObjectsFromSuperView:self.mArray];
//        [self.mArray addObject:tempLabel];
//        if (self.repeatNum == -1) {
//            //销毁定时器并清除之前数字视图
//            [self.timer invalidate];
//            self.timer = nil;
//            [self removeAllObjectsFromSuperView:self.mArray];
//            //开启对勾动画
//            [self openSuccessAnimation];
//        }
//    }];
//

}


#pragma mark - 开启成功标志动画加
- (void)openSuccessAnimation{
    
//    [UIView animateWithDuration:1.0f animations:^{
//        self.shopView.bottomWhiteView.circleVIew.successImageView.alpha = 1;
//        self.shopView.bottomWhiteView.topLabel.alpha = 0;
//        self.shopView.bottomWhiteView.bottomLabel.alpha = 0;
//    } completion:^(BOOL finished) {
//
//        [self.shopView.bottomWhiteView.topLabel removeFromSuperview];
//        [self.shopView.bottomWhiteView.bottomLabel removeFromSuperview];
//        [UIView animateWithDuration:1.0f animations:^{
//            CGAffineTransform transforom = CGAffineTransformMakeScale(1.25, 1.25);
//            self.shopView.bottomWhiteView.circleVIew.successImageView.transform = transforom;
//        } completion:^(BOOL finished) {
//            //self.successImageView.transform = CGAffineTransformIdentity;//回复原始状态(动画效果较差)
//            [UIView animateWithDuration:1.0f animations:^{
//                CGAffineTransform transforom = CGAffineTransformMakeScale(0.8, 0.8);
//                self.shopView.bottomWhiteView.circleVIew.successImageView.transform = transforom;
//            } completion:^(BOOL finished) {
//
//                //实现顶点上拉缩放
//                [UIView animateWithDuration:0.5f animations:^{
//                    [self.shopView.bottomWhiteView ShopopingCarOrderLCViewTopMoveAnimationOpen];
//                } completion:^(BOOL finished) {
//
//                    //改变订单提交成功字体透明度+订单界面滑入动画
//                    [self openWordAlphaAnimationAndOrderViewSliderAnimation];
//                }];
//            }];
//
//        }];
//    }];
}


#pragma mark - 改变订单提交成功字体透明度+订单界面滑入动画
- (void)openWordAlphaAnimationAndOrderViewSliderAnimation{
    
//    [UIView animateWithDuration:0.5f animations:^{
//
//        //改变字体透明度
//        [self.shopView.bottomWhiteView ShopopingCarOrderLCViewAlphaChange];
//    } completion:^(BOOL finished) {
//        [self.shopView.bottomWhiteView ShopopingCarOrderLCViewOrderSolutionView];
//        [UIView animateWithDuration:1.0f animations:^{
//            //线条滑动切入订单结果视图
//            [self.shopView.bottomWhiteView.orderOverView ShopCircleOrderOverViewSliderAnimation];
//        } completion:^(BOOL finished) {
//            //删除遮罩
//            [self.shopView.bottomWhiteView.orderOverView ShopCircleOrderOverViewRemoveMaskAnimation];
//        }];
//    }];
}


- (UILabel *)LabelWithNum:(NSInteger)num WithFrame:(CGRect)frame{
    
    UILabel *startLabel = [[UILabel alloc]initWithFrame:frame];
    startLabel.text = num>=0?[NSString stringWithFormat:@"%ld",num]:@"";
    startLabel.textAlignment = NSTextAlignmentCenter;
    startLabel.textColor = [UIColor blackColor];
    startLabel.font = [UIFont systemFontOfSize:SCREEN_W*0.20];
    return startLabel;
}


- (void)removeAllObjectsFromSuperView:(NSMutableArray *)labelArray{
    
    for (int i = 0; i<labelArray.count; i++) {
        [[labelArray objectAtIndex:i] removeFromSuperview];
    }
}



@end

